package com.example.zhugenew.adapter.newhouses;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.zhugenew.R;
import com.example.zhugenew.bean.newhouses.NewHouseHotListBean;

import java.util.List;

public class NewHouseHotlistAdapter extends RecyclerView.Adapter<NewHouseHotlistAdapter.ViewHolder> {
    private List<NewHouseHotListBean.DataBean> list;
    private Context context;

    public NewHouseHotlistAdapter(List<NewHouseHotListBean.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.layout_newhouse_hotlist_item, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.desc.setText(list.get(position).getDesc());
        holder.name.setText(list.get(position).getName());
        Glide.with(context).load(list.get(position).getImg_url()).into(holder.image);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView name;
        private final TextView desc;
        private final ImageView image;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            desc = itemView.findViewById(R.id.hotlist_desc);
            name = itemView.findViewById(R.id.hotlist_name);
            image = itemView.findViewById(R.id.hotlist_image);
        }
    }
}
 